/*
 * ConvertMugenToJavaView.java
 */

package convertmugentojava;

import java.io.File;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.Task;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;

/**
 * The application's main frame.
 */
public class ConvertMugenToJavaView extends FrameView {

    public ConvertMugenToJavaView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ConvertMugenToJavaApp.getApplication().getMainFrame();
            aboutBox = new ConvertMugenToJavaAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ConvertMugenToJavaApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new JCTextArea();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        Limpar = new javax.swing.JMenuItem();
        jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N

        jTextField1.setEditable(false);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(convertmugentojava.ConvertMugenToJavaApp.class).getContext().getResourceMap(ConvertMugenToJavaView.class);
        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(convertmugentojava.ConvertMugenToJavaApp.class).getContext().getActionMap(ConvertMugenToJavaView.class, this);
        jButton1.setAction(actionMap.get("browse")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("jButton1.toolTipText")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jTextArea1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextArea1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTextArea1);

        jButton2.setAction(actionMap.get("startConversion")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setToolTipText(resourceMap.getString("jButton2.toolTipText")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(4, 4, 4)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 232, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        jPopupMenu1.setName("jPopupMenu1"); // NOI18N

        Limpar.setAction(actionMap.get("cleanLog")); // NOI18N
        Limpar.setText(resourceMap.getString("Limpar.text")); // NOI18N
        Limpar.setName("Limpar"); // NOI18N
        jPopupMenu1.add(Limpar);

        jCheckBoxMenuItem1.setAction(actionMap.get("setAutoScroll")); // NOI18N
        jCheckBoxMenuItem1.setSelected(true);
        jCheckBoxMenuItem1.setText(resourceMap.getString("jCheckBoxMenuItem1.text")); // NOI18N
        jCheckBoxMenuItem1.setToolTipText(resourceMap.getString("jCheckBoxMenuItem1.toolTipText")); // NOI18N
        jCheckBoxMenuItem1.setName("jCheckBoxMenuItem1"); // NOI18N
        jPopupMenu1.add(jCheckBoxMenuItem1);

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextArea1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextArea1MouseClicked
        if (evt.getButton() == 3)
        {
            jPopupMenu1.show(jTextArea1, evt.getX(), evt.getY());
        }
    }//GEN-LAST:event_jTextArea1MouseClicked

    private JFileChooser fc;

    @Action
    public void browse() 
    {
        fc = new JFileChooser("C:/Documents and Settings/moacirj/Desktop/mugen");
        FileFilter ff = new FileFilter()
        {
            @Override
            public boolean accept(File f) {
                return f.isDirectory() || f.getName().endsWith(".def");
            }

            @Override
            public String getDescription() {
                return "Arquivo de definições do Mugen";
            }
        };
        fc.setFileFilter(ff);
        fc.showOpenDialog(null);
        if (fc.getSelectedFile() != null)
            jTextField1.setText(fc.getSelectedFile().getAbsolutePath());
    }

    @Action
    public Task startConversion()
    {
        return new StartConversionTask(getApplication());
    }

    private class StartConversionTask extends org.jdesktop.application.Task<Object, Void>
    {
        StartConversionTask(org.jdesktop.application.Application app) {
            super(app);
        }
        
        @Override protected Object doInBackground()
        {
            try
            {
                toggleButtons(false);
                if (fc == null || fc.getSelectedFile() == null)
                {
                    jTextArea1.append("Nenhum personagem selecionado.");
                    browse();
                }
                if (fc.getSelectedFile() != null)
                {
                    startConversionConfirmed();
                }
                else
                {
                    jTextArea1.append("Impossível continuar sem um personagem selecionado.");
                    jTextArea1.append("Por favor selecione um.");
                }
                toggleButtons(true);
            }catch(Exception e)
            {
                toggleButtons(true);
            }
            return null;
        }
    }

    private void startConversionConfirmed()
    {
        jTextArea1.append("Start conversion...");
        String name = "";
        String author = "";
        String displayName = "";
        try
        {
            File def = fc.getSelectedFile();
            FileReader fr = new FileReader(def);
            BufferedReader br = new BufferedReader(fr);
            List<String> fileNames = new ArrayList<String>();
            String line = "";
            while(true)
            {
                line = br.readLine();
                if (line == null)
                    break;
                else
                {
                    if (line.toLowerCase().startsWith("name"))
                        name = getInfoPar(line);
                    if (line.toLowerCase().startsWith("author"))
                        author = getInfoPar(line);
                    if (line.toLowerCase().startsWith("displayname"))
                        displayName  = getInfoPar(line);
                    if (
                        line.toLowerCase().startsWith("cns") ||
                        line.toLowerCase().startsWith("cmd") ||
                        line.toLowerCase().startsWith("st") ||
                        line.toLowerCase().startsWith("stcommon") ||
                        line.toLowerCase().startsWith("ai"))
                    {
                        if (!fileNames.contains(getFilePar(line)))
                            fileNames.add(getFilePar(line));
                    }
                }
            }
            
            jTextArea1.append("Nome = "+name);
            jTextArea1.append("Nome Completo = "+displayName);
            jTextArea1.append("Autor = "+author);
            jTextArea1.append("Carregando arquivos... ");
            progressBar.setValue(0);
            int i = 1;
            for (String a : fileNames)
            {
                jTextArea1.append(a+ " "+i+"/"+fileNames.size());
                JCFile file = new JCFile(fc.getSelectedFile().getAbsolutePath());
                File charFile = new File(file.getFolder()+"/"+a);
				System.out.println("-----"+a);
				if (a.equals("common1.cns") && !charFile.exists())
				{
					jTextArea1.append("Pulando commom1.cns");
					continue;
				}
                boolean retorno = false;
                if (charFile.getName().endsWith(".cns"))
                    retorno = convertCNSFile(charFile);
                else
                    retorno = convertCMDFile(charFile);
                if (retorno)
                {
                    i++;
                    progressBar.setValue((i*100)/fileNames.size());
                    jTextArea1.append("Ok");
                }
            }
        }
        catch(FileNotFoundException f)
        {
            f.printStackTrace();
            jTextArea1.append("Erro - Arquivo def não encontrado");
        }
        catch(IOException i)
        {
            i.printStackTrace();
            jTextArea1.append("Erro - Arquivo def não encontrado");
        }
        catch(Exception e)
        {
            e.printStackTrace();
            jTextArea1.append("Erro não identificado.\n"+e.getMessage());
        }
    }

    private Boolean convertCNSFile(File cns) throws Exception
    {
        FileReader fr = new FileReader(cns);
        BufferedReader br = new BufferedReader(fr);
        String line = "";
        StringBuffer sb = new StringBuffer();
        List<String> states = new ArrayList<String>();
        LinkedHashMap<String, String> stateCodes = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> dataParams = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> sizeParams = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> velocityParams = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> movementParams = new LinkedHashMap<String, String>();
        String stateName = null;
        jTextArea1.append("Carregando lista de states...");
        int searchingState = 0;
        if (br.markSupported())
            br.mark(1);
        while(true)
        {
            line = br.readLine();
            if (line == null)
                break;
            else
            {
                if (line.toLowerCase().startsWith("[data]")) {
                    searchingState = searchingForData;
                    continue;
                }
                if (line.toLowerCase().startsWith("[size")) {
                    searchingState = searchingForSize;
                    continue;
                }
                if (line.toLowerCase().startsWith("[velocity")) {
                    searchingState = searchingForVelocity;
                    continue;
                }
                if (line.toLowerCase().startsWith("[movement")) {
                    searchingState = searchingForMovement;
                    continue;
                }
                if (line.toLowerCase().startsWith("[statedef")) {
                    searchingState = searchingForState;
                }
                
                if (searchingState == searchingForData)
                {
                    if (line.indexOf("=") != -1)
                    {
                        String par = line.split("=")[1];
                        if (par.indexOf(";") != -1)
                            par = par.substring(0, par.indexOf(";")).trim()+"//"+line.substring(line.indexOf(";")+1);
                        else
                            par = par.trim();
                        dataParams.put(line.split("=")[0].trim(), par);
                    }
                }

                if (searchingState == searchingForSize)
                {
                    if (line.indexOf("=") != -1)
                    {
                        String par = line.split("=")[1];
                        if (par.indexOf(";") != -1)
                            par = par.substring(0, par.indexOf(";")).trim()+"//"+line.substring(line.indexOf(";")+1);
                        else
                            par = par.trim();
                        sizeParams.put(line.split("=")[0].trim(), par);
                    }
                }

                if (searchingState == searchingForVelocity)
                {
                    if (line.indexOf("=") != -1)
                    {
                        String par = line.split("=")[1];
                        if (par.indexOf(";") != -1)
                            par = par.substring(0, par.indexOf(";")).trim()+"//"+line.substring(line.indexOf(";")+1);
                        else
                            par = par.trim();
                        velocityParams.put(line.split("=")[0].trim(), par);
                    }
                }

                if (searchingState == searchingForMovement)
                {
                    if (line.indexOf("=") != -1)
                    {
                        String par = line.split("=")[1];
                        if (par.indexOf(";") != -1)
                            par = par.substring(0, par.indexOf(";")).trim()+"//"+line.substring(line.indexOf(";")+1);
                        else
                            par = par.trim();
                        movementParams.put(line.split("=")[0].trim(), par);
                    }
                }
                
                if (searchingState == searchingForState && line.toLowerCase().startsWith("[statedef"))
                {
                    if (stateName != null)
                        stateCodes.put(stateName, sb.toString());
                    stateName = line.substring(line.indexOf("[statedef")+10, line.lastIndexOf("]")).trim();
					if (stateName.indexOf(",") != -1)
						stateName = stateName.substring(0, stateName.indexOf(","));
                    states.add(stateName);
                    sb.delete(0, sb.length());
                }
                else if (searchingState == searchingForState && stateName != null)
                {
                    sb.append(line+"\n");
                }
            }
        }
        if (stateName != null)//adiciona o ultimo state
            stateCodes.put(stateName, sb.toString());
        for(String key : stateCodes.keySet())
        {
            jTextArea1.append("public static void stateDef"+key+"()");
            jTextArea1.append("{");
            String[] lines = stateCodes.get(key).split("\n");
            for (String state : lines)
            {
                LinkedHashMap<String, String> triggers = new LinkedHashMap<String, String>();
                for (String codeLine : lines)
                {
                    if (codeLine.toLowerCase().startsWith("trigger"))
                    {
                        String name = codeLine.substring(0, codeLine.indexOf("=")).trim();
                        String par = codeLine.substring(codeLine.indexOf("=")+1);
                            if (par.indexOf(";") != -1)
                                par = par.substring(0, par.indexOf(";")).trim()+"//"+codeLine.substring(codeLine.indexOf(";")+1);
                            else
                                par = par.trim();
                        if (!triggers.containsKey(name))
                            triggers.put(name, par);
                        else
                            triggers.put(name, triggers.get(name)+" || "+par);
                    }
                }
            }
            
            jTextArea1.append("}");
        }
        return true;
    }



    private Boolean convertCMDFile(File cmd) throws Exception
    {
        FileReader fr = new FileReader(cmd);
        BufferedReader br = new BufferedReader(fr);
        String line = "";
        while(true)
        {
            line = br.readLine();
            if (line == null)
                break;
            else
            {
                
            }
        }
        return true;
    }

    private void toggleButtons(boolean enable)
    {
        jButton1.setEnabled(enable);
        jButton2.setEnabled(enable);
    }

    private String getInfoPar(String line)
    {
        String temp = line;
        if (temp.indexOf(";") == -1)
            temp = temp.substring(temp.indexOf("\"")+1, temp.lastIndexOf("\""));
        else
        {
            temp = temp.substring(temp.indexOf("\"")+1, temp.lastIndexOf(";"));
            temp = temp.substring(0, temp.lastIndexOf("\""));
        }
        return temp;
    }

    private String getFilePar(String line)
    {
        String temp = line;
        if (temp.indexOf(";") == -1)
            temp = temp.substring(temp.indexOf("=")+1);
        else
            temp = temp.substring(temp.indexOf("=")+1, temp.lastIndexOf(";"));
        temp = temp.trim();
        return temp;
    }

    @Action
    public Task cleanLog() {
        return new CleanLogTask(getApplication());
    }

    private class CleanLogTask extends org.jdesktop.application.Task<Object, Void> {
        CleanLogTask(org.jdesktop.application.Application app) {
            super(app);
        }
        @Override protected Object doInBackground() 
        {
            jTextArea1.setText("");
            return null;
        }
    }

    @Action
    public void setAutoScroll()
    {
        jTextArea1.setAutoScroll(jCheckBoxMenuItem1.isSelected());
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem Limpar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private JCTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    public static final int searchingForData = 1;
    public static final int searchingForSize = 2;
    public static final int searchingForVelocity = 3;
    public static final int searchingForMovement = 4;
    public static final int searchingForState = 5;

    private JDialog aboutBox;
}
